﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UsrCustomFun
{
    public class UserWaitBox
    {
        #region [函数]
        /// <summary>
        /// 窗体是否打开：1为打开，0为关闭
        /// </summary>
        private static int intmsg = 0;
        /// <summary>
        /// 加载等待窗体
        /// </summary>
        private static UsrWaitForm.UsrWaitForms fm1;
        #endregion

        #region [方法]
        /// <summary>
        /// 自定义消息--消息内容
        /// </summary>
        /// <param name="MsgContent">消息内容</param>
        /// <returns></returns>
        public static int UsrShow(string MsgContent)
        {
            if (fm1 == null || fm1.IsDisposed)
            {
                fm1 = new UsrCustomFun.UsrWaitForm.UsrWaitForms();
                fm1.MsgContent = MsgContent;//设置消息窗体内容
                try
                {
                    fm1.BringToFront();
                    fm1.Show();
                    intmsg = 1;
                }
                catch (Exception ec)
                {
                    UserMessageBox.UsrShow("等待消息窗体打开失败！", "系统错误", ec.Message.ToString());
                    intmsg = 0;
                }
            }
            return intmsg;
        }

        /// <summary>
        /// 自定义消息--消息内容|窗体标题
        /// </summary>
        /// <param name="MsgContent">消息内容</param>
        /// <param name="FormText">窗体标题</param>
        /// <returns></returns>
        public static int UsrShow(string MsgContent, string FormText)
        {
            if (fm1 == null || fm1.IsDisposed)
            {
                fm1 = new UsrCustomFun.UsrWaitForm.UsrWaitForms();
                fm1.MsgContent = MsgContent;//设置消息窗体内容
                fm1.FormTitle = FormText;//设置窗体标题
                try
                {
                    fm1.BringToFront();
                    fm1.Show();
                    intmsg = 1;
                }
                catch (Exception ec)
                {
                    UserMessageBox.UsrShow("等待消息窗体打开失败！", "系统错误", ec.Message.ToString());
                    intmsg = 0;
                }
            }
            return intmsg;
        }

        public static int UsrShow(string MsgContent, string FormText,string MsgTitles)
        {
            if (fm1 == null || fm1.IsDisposed)
            {
                fm1 = new UsrCustomFun.UsrWaitForm.UsrWaitForms();
                fm1.MsgContent = MsgContent;//设置消息窗体内容
                fm1.FormTitle = FormText;//设置窗体标题
                fm1.MsgTitle = MsgTitles;//设置消息栏标题
                try
                {
                    fm1.BringToFront();
                    fm1.Show();
                    intmsg = 1;
                }
                catch (Exception ec)
                {
                    UserMessageBox.UsrShow("等待消息窗体打开失败！", "系统错误", ec.Message.ToString());
                    intmsg = 0;
                }
            }
            return intmsg;
        }

        /// <summary>
        /// 关闭窗体
        /// </summary>
        /// <returns></returns>
        public static void UsrClose()
        {
            if (intmsg == 1)
            {
                fm1.Close();
            }
        }

        #endregion
    }
}
